package com.ndp.fb.fbagent.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.ndp.fb.constant.CommonConstants;
import com.ndp.fb.fbagent.service.AccountFBService;
import com.ndp.fb.model.fbagent.param.APIPriority;
import com.ndp.fb.model.fbagent.param.ApiCallBackTarget;
import com.ndp.fb.model.fbagent.param.FacebookParam;
import com.ndp.fb.model.fbagent.result.entrustaccount.AccountIns;
import com.restfb.Parameter;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by Evan on 12/15/2015.
 */
@Service
public class AccountFBServiceImpl extends AbstractFBagentService implements AccountFBService {

    @Override
    public void syncAccountIns(String accessToken, Long fbAccountId)
    {
        String fields = "id,is_published,owner_business,username,has_profile_picture";
        Map<String, String> equipment = new HashMap<>();
        equipment.put("fbActId", fbAccountId + "");
        FacebookParam requestParam = new FacebookParam();
        requestParam.setFields(fields);
        requestParam.setLimit(CommonConstants.NUM_INT_500);
        requestParam.setApiPriorityCode(APIPriority.SyncIns.getCode());
        requestParam.setEquipment(equipment);
        requestParam.setApiCallbackTargetType(ApiCallBackTarget.AutoControl.SyncIns.getTargetType());
        requestParam.setCallBack(true);
        requestParam.setResultClass(AccountIns.class);
        requestParam.setFbAccountId(fbAccountId);
        Parameter[] parameters = this.adapterArray(requestParam);
        String uri = "/act_" + fbAccountId + "/instagram_accounts";
        makeGetRequest(uri, accessToken, parameters);
    }
}
